package cn.vcjf.weapp.api.active.controller;


import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.active.entity.UserActive;
import cn.vcjf.weapp.api.active.service.UserActiveService;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-26
 */
@Controller
@RequestMapping("/active/userActive")
public class UserActiveController {
	@Resource
	private UserActiveService userActiveService;

	@RequestMapping("/addUserActive")
	@ResponseBody
	public TableResult addUserActive(UserActive userActive) {
		userActive.preInsert();
		boolean b = userActiveService.insert(userActive);
		return TableResult.Result(b);
	}

	@RequestMapping("/updateUserActive")
	@ResponseBody
	public TableResult updateUserActive(UserActive userActive) {
		userActive.preUpdate();
		boolean b = userActiveService.updateById(userActive);
		return TableResult.Result(b);
	}

	@RequestMapping("/findUserActiveOne")
	@ResponseBody
	public TableResult findUserActiveOne(UserActive userActive) {

		EntityWrapper<UserActive> wrapper = userActive.getQueryWrapper();
		//Todo

		UserActive result = userActiveService.selectOne(wrapper);

		return TableResult.OKResult(result);
	}

	/**
	 * 获取用户的活动列表
	 * @param userActive
	 * @return
	 */
	@RequestMapping("/findUserActiveList")
	@ResponseBody
	public TableResult findUserActiveList(UserActive userActive) {

		Page<UserActive> page = userActive.getPageInfo();

		List<UserActive> list = userActiveService.selectUserActiveList(page, userActive);

		return TableResult.OKResult(page.setRecords(list));
	}

	/**
	 * 获取活动的参与人列表
	 * @param userActive
	 * @return
	 */
	@RequestMapping("/selectActiveUserList")
	@ResponseBody
	public TableResult selectActiveUserList(UserActive userActive) {
		List<UserActive> list = userActiveService.selectActiveUserList( userActive);

		return TableResult.OKResult(list);
	}

	@RequestMapping("/deleteUserActive")
	@ResponseBody
	public TableResult deleteUserActive(UserActive userActive) {
		userActive.preUpdate();
		boolean b = userActiveService.deleteById(userActive.getId());
		return TableResult.Result(b);
	}

}
